package com.zhuannimei.fragment;

import java.util.HashMap;
import java.util.Map;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.zhuannimei.R;
import com.zhuannimei.net.RequestServerData;
import com.zhuannimei.utility.JsonUtil;
import com.zhuannimei.utility.UserData;
import com.zhuannimei.utility.WuLog;

public class Fragment4 extends BaseFragment implements OnClickListener{
	
	private static final String TAG = "Fragment4";

	private LinearLayout mytaobao;
	private Button btExit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.tab_setting, container, false);
		return super.onCreateView(inflater, container, savedInstanceState) ;
	}

	@Override
	public void onStart() {
		super.onStart();
		mTitlePane.setTitle("其他");
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	protected void initViews() {
		mytaobao = (LinearLayout) findViewById(R.id.mytaobao);
		btExit = (Button) findViewById(R.id.logout);
	}

	@Override
	protected void initEvents() {
		mytaobao.setOnClickListener(Fragment4.this);
		btExit.setOnClickListener(this);
	}

	@Override
	protected void initData() {

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.mytaobao:
			WuLog.i(TAG, "购买记录");
			putAsyncTask(new AsyncTask<Void, Void, String>() {
				
				@Override
				protected void onPreExecute() {
					super.onPreExecute();
				}

				@Override
				protected String doInBackground(Void... params) {
					Map<String, String> map = new HashMap<String, String>();
					map.put("userId", UserData.getInstance().getUserUserId());
					map.put("timestamp", "1");
					Map<String, String> map2 = JsonUtil.getJsonMap(map);
					return RequestServerData.getHistorys(map2);
				}
				@Override
				protected void onPostExecute(String result) {
					super.onPostExecute(result);
					WuLog.i(TAG, "执行结束，服务器返回的结果=====" + result);
				}
			});
		case R.id.logout:
			getActivity().finish();
			UserData.getInstance().saveUserUserId("");
			break;
		default:
			break;
		}
	}

}
